/*    */ package com.newcrm.db;
/*    */ 
/*    */ import java.sql.Connection;
/*    */ import java.sql.SQLException;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import org.apache.commons.dbutils.DbUtils;
/*    */ import org.apache.commons.dbutils.MyMapListHandler;
/*    */ import org.apache.commons.dbutils.QueryRunner;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class QisoukeManager
/*    */ {
/* 21 */   private static Logger logger = Logger.getLogger(QisoukeManager.class
/* 22 */     .getName());
/*    */ 
/*    */   public List<Map<String, Object>> list(int companyId, String userId)
/*    */   {
/* 34 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 35 */     if (conn == null) {
/* 36 */       return null;
/*    */     }
/*    */ 
/* 39 */     QueryRunner runner = new QueryRunner();
/*    */     try
/*    */     {
/* 43 */       List result = (List)runner.query(conn, 
/* 44 */         "SELECT KeyWord, CurrentPage, SearchDate FROM T_Yunsou_History WHERE CompanyId = ? AND UserId = ? ORDER BY SearchDate DESC", new MyMapListHandler(), new Object[] { 
/* 45 */         Integer.valueOf(companyId), userId });
/*    */ 
/* 47 */       if (result.size() > 10) {
/* 48 */         int rowNum = result.size() - 10;
/* 49 */         String sql = "DELETE FROM T_Yunsou_History WHERE CompanyId = ? AND UserId = ? ORDER BY SearchDate ASC LIMIT " + rowNum;
/* 50 */         runner.update(conn, sql, new Object[] { Integer.valueOf(companyId), userId });
/*    */       }
/*    */ 
/* 53 */       return result;
/*    */     } catch (SQLException e) {
/* 55 */       logger.warn("list search history failed", e);
/*    */     } finally {
/*    */       try {
/* 58 */         DbUtils.close(conn);
/*    */       } catch (SQLException e) {
/* 60 */         logger.warn("close conn failed", e);
/*    */       }
/*    */     }
/*    */ 
/* 64 */     return null;
/*    */   }
/*    */ 
/*    */   public int add(String keyWord, int currentPage, int companyId, String userId)
/*    */   {
/* 77 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 78 */     if (conn == null) {
/* 79 */       return -1;
/*    */     }
/*    */ 
/* 82 */     QueryRunner runner = new QueryRunner();
/*    */     try {
/* 84 */       return runner.update(conn, "INSERT INTO T_Yunsou_History (KeyWord, CurrentPage, SearchDate, CompanyId, UserId) VALUES (?,?,NOW(),?,?) ON DUPLICATE KEY UPDATE CurrentPage = ?, SearchDate = NOW()", new Object[] { keyWord, 
/* 85 */         Integer.valueOf(currentPage), Integer.valueOf(companyId), userId, Integer.valueOf(currentPage) });
/*    */     }
/*    */     catch (SQLException e) {
/* 88 */       logger.warn("Get the YunSou history failed", e);
/*    */     } finally {
/*    */       try {
/* 91 */         DbUtils.close(conn);
/*    */       } catch (SQLException e) {
/* 93 */         logger.warn("close conn failed", e);
/*    */       }
/*    */     }
/* 96 */     return 0;
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.QisoukeManager
 * JD-Core Version:    0.6.1
 */